package com.ruoyi.material.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.BaseLabel;
import com.ruoyi.material.service.IBaseLabelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签类型Controller
 * 
 * @author ruoyi
 * @date 2021-07-23
 */
@RestController
@RequestMapping("/material/label")
public class BaseLabelController extends BaseController
{
    @Autowired
    private IBaseLabelService baseLabelService;

    /**
     * 查询标签类型列表
     */
    @PreAuthorize("@ss.hasPermi('material:label:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseLabel baseLabel)
    {
        startPage();
        List<BaseLabel> list = baseLabelService.selectBaseLabelList(baseLabel);
        return getDataTable(list);
    }

    /**
     * 导出标签类型列表
     */
    @PreAuthorize("@ss.hasPermi('material:label:export')")
    @Log(title = "标签类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseLabel baseLabel)
    {
        List<BaseLabel> list = baseLabelService.selectBaseLabelList(baseLabel);
        ExcelUtil<BaseLabel> util = new ExcelUtil<BaseLabel>(BaseLabel.class);
        return util.exportExcel(list, "标签类型数据");
    }

    /**
     * 获取标签类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:label:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseLabelService.selectBaseLabelById(id));
    }

    /**
     * 新增标签类型
     */
    @PreAuthorize("@ss.hasPermi('material:label:add')")
    @Log(title = "标签类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseLabel baseLabel)
    {
        return toAjax(baseLabelService.insertBaseLabel(baseLabel));
    }

    /**
     * 修改标签类型
     */
    @PreAuthorize("@ss.hasPermi('material:label:edit')")
    @Log(title = "标签类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseLabel baseLabel)
    {
        return toAjax(baseLabelService.updateBaseLabel(baseLabel));
    }

    /**
     * 删除标签类型
     */
    @PreAuthorize("@ss.hasPermi('material:label:remove')")
    @Log(title = "标签类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseLabelService.deleteBaseLabelByIds(ids));
    }
}
